package com.bs.jianli.util.interceptor;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.bs.jianli.entity.User;
import com.bs.jianli.util.exception.NotUserException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 小姚
 * @pakeageName:com.bs.jianli.util.interceptor
 * @ClassName:MyInterceptor
 * @Descirption:
 * @data 2023/1/13 18:45
 */
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user =(User) session.getAttribute("user");
        if(user==null){
            throw new NotUserException("用户未登录");
        }
        return true;
    }
}
